//
//  Kylin_NavgationViewController.m
//  03-BuDeJie-2 TabBar设置
//
//  Created by Kylin on 16/2/4.
//  Copyright © 2016年 kylin. All rights reserved.
//

#import "Kylin_NavgationViewController.h"

@interface Kylin_NavgationViewController ()<UIGestureRecognizerDelegate>

@end

@implementation Kylin_NavgationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.interactivePopGestureRecognizer.delegate = self;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    
    // 当前导航控制器发果是PUSH进来的控制器就执行统一设置返回按钮
    
    if (self.childViewControllers.count >= 1) {
        
        //  自定义一个按钮
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"返回" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        [button setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
        [button sizeToFit];
        
        //点击事件
        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        button.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0); // 设置边框偏移量,按钮靠左边
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
        
        // push 控制器的时侯藏tabBar
        viewController.hidesBottomBarWhenPushed = YES;
        
    }
    
    [super pushViewController:viewController animated:animated];
}

- (void)back{
    
    [self popViewControllerAnimated:YES];
}

#pragma mark- 控制器开始滑动进调用
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    
    return self.childViewControllers.count > 1;
}
@end
